var dayjs = require('dayjs');
import {selectedYear} from './createYearList.js'
import {selectedMonth} from './createMonthList.js'
const nowYear = dayjs().get('year')
const nowMonth = dayjs().get('month') + 1;
const nowDate = dayjs().get('date');
const yearSpan = selectedYear.querySelector('span')
const monthSpan = selectedMonth.querySelector('span')
const other = function other(el,type){
    [...el].forEach(item=>{
        if(type == 'list'){
            if(item.innerHTML == `${nowYear}年` || item.innerHTML ==`${nowMonth}月`){
                item.classList.add('activeLi','selectLi')
            }
        }
        else if(type == 'panel'){
            if((item.innerHTML == `${nowMonth}月` && yearSpan.innerHTML == `${nowYear}年`) || (item.innerHTML==`${nowDate}` && item.style.color == '' && monthSpan.innerHTML == `${nowMonth}月`)){
                item.classList.add('activeTd','selectTd')
                item.style.borderColor = '#1890FF'
            }
        }
        item.addEventListener('click',function(){
            if(type == 'panel'){
                [...el].forEach(item=> {
                    item.classList.remove('activeTd')
                });
                this.classList.add('activeTd');
                this.classList.remove('overTd');
            }
            else if(type == 'list'){
                [...el].forEach(item=> {
                    item.classList.remove('activeLi')
                });
                this.classList.add('activeLi');
                this.classList.remove('overLi');
            }
  
        },false);


        item.addEventListener('mousemove',function(){
            if(type == 'panel'){
                if(!this.classList.contains('activeTd')){
                    this.classList.add('overTd');
                }
            }
            else if(type == 'list'){
                if(!this.classList.contains('activeLi')){
                    this.classList.add('overLi');
                }
            }
        },false);


        item.addEventListener('mouseleave',function(){
            if(type == 'panel'){
                this.classList.remove('overTd');
            }
            else if(type == 'list'){
                this.classList.remove('overLi');
            }
        },false)
    })
}

export {other}